/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kifas.service;

import com.kifas.model.xml.KontrakModel;
import com.kifas.model.xml.KontrakPembelianModel;
import com.kifas.model.xml.PembelianModel;
import com.kifas.model.xml.PersistStatus;
import com.kifas.ui.util.ServiceConstants;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.apache.log4j.Logger;

/**
 *
 * @author dhamarsu
 */
public class PembelianService {
    private static Logger log = Logger.getLogger(MasterService.class);
    private String serviceUrl  = ServiceConstants.URL_CONTROLLER;
    private Client restClient;

    public PembelianService() {
        restClient = Client.create();
    }

    public PersistStatus setPembelian(PembelianModel pm){
        WebResource webResource = restClient.resource(serviceUrl + ServiceConstants.URL_PEMBELIAN);
        PersistStatus persistStatus = webResource.accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML).post(PersistStatus.class, pm);
        return  persistStatus;
    }

    public List<PembelianModel> getPembelians() {
        WebResource webResource = restClient.resource(serviceUrl + ServiceConstants.URL_PEMBELIAN);
        return webResource.get(new GenericType<List<PembelianModel>>(){});
    }

    public List<KontrakModel> getKontraks() {
        WebResource webResource = restClient.resource(serviceUrl + ServiceConstants.URL_KONTRAKS);
        return webResource.get(new GenericType<List<KontrakModel>>(){});
    }

    public List<KontrakPembelianModel> getKontrakPembelians() {
        WebResource webResource = restClient.resource(serviceUrl + ServiceConstants.URL_KONTRAKS);
        return webResource.get(new GenericType<List<KontrakPembelianModel>>(){});
    }

}
